/*
 * @Author: guoyangf
 * @Date: 2020-08-07 16:24:27
 * @LastEditTime: 2020-08-07 17:17:05
 * @Description: file content
 */
function socketMesg(props, mesg) {
    let sagaStatus = mesg.error ? "1" : "0";
    // this.setState({ sagaStatus });
    const refreshData = mesg.refreshData || [];
    const { showDetailPage } = this.state;
    if (sagaStatus === "0") {
        //刷新
        this.queryData();
    }
    if (showDetailPage) {
        refreshData.forEach(async data => {
            //卡片也需要更新缓存数据 根据_businessPk和当前数据的busiid来判断是否还打开了此单据
            const { _businessPk } = data;
            if (_businessPk) {
                let { busiid, module } = this.currentRowData;
                let row = this.data.listRows.find(row => row.values.busiid.value === data._businessPk);
                if (row) {
                    row.values.saga_status.value = data.saga_status;
                    row.values.saga_gtxid.value = data.saga_gtxid;
                    if (sagaStatus === "0") {//saga事务正确
                        let response = await this.requestApi.updateTs({
                            pk_task: row.values.pk_task.value,

                        })
                        let _ts = response.data.data;
                        row.values.ts.value = _ts;
                    }
                    if (_businessPk === busiid.value) {
                        this.setState({ currentRowSagaStatus: sagaStatus })
                    }
                    //微服务环境下不刷新工单
                    if (module.value !== "webdbl") {
                        // reloadBillPage.call(this);
                    }
                }
            }
        })
    }

}


function handleSagaErrorClick() {
    const { saga_gtxid, busiid, billtypecode }  = this.currentRowData;

    this.setState({
        billErrorInfoBySaga: {
            show: true,
            pk: (busiid && busiid.value) || "",
            gtxid: (saga_gtxid && saga_gtxid.value) || "",
            type: (billtypecode && billtypecode.value) || ""
        }
    });
}

export { socketMesg, handleSagaErrorClick }